<template>
	<view class="cart-container" v-if="cart.length">
		<!-- 收货地址区域 -->
		<my-address></my-address>

		<!-- 购物车商品列表的标题区域 -->
		<view class="cart-title">
			<!-- 左侧的图标 -->
			<uni-icons type="shop" size="18"></uni-icons>
			<!-- 描述文本 -->
			<text class="cart-title-text">购物车</text>
		</view>

		<!-- 商品列表 -->
		<view class="goods-list">
			<uni-swipe-action>
				<block v-for="(item, i) in cart" :key="i">
					<uni-swipe-action-item :right-options="options" @click="deleteGoods(item.goods_id)">
						<my-goods :goods="item" show-radio @radio-change="radioChange" show-num
							@num-change="numChange"></my-goods>
					</uni-swipe-action-item>
				</block>
			</uni-swipe-action>
		</view>

		<!-- 底部结算 -->
		<my-settle></my-settle>
	</view>
	<view v-else>11</view>
</template>

<script>
	import tabbarMinxin from '../../mixins/tabbar.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		mixins: [tabbarMinxin],
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f00'
					}
				}]
			};
		},
		computed: {
			...mapState('m_cart', ['cart'])
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'removeGoodsById']),

			radioChange(goods) {
				this.updateGoodsState(goods)
			},
			numChange(goods) {
				this.updateGoodsCount(goods)
			},
			deleteGoods(goods_id) {
				this.removeGoodsById(goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.cart-title {
		height: 40px;
		display: flex;
		align-items: center;
		font-size: 14px;
		padding-left: 5px;
		border-bottom: 1px solid #efefef;

		.cart-title-text {
			margin-left: 10px;
		}
	}

	.cart-container {
		padding-bottom: 50px;
	}
</style>